package com.csgc.camera.util

import android.content.Context
import android.content.res.Resources
import android.util.TypedValue
import android.view.Display
import android.view.WindowManager


object ViewUtils {


    /**
     * 获取屏幕宽度大小，单位px

     * @param context
     * *
     * @return
     */
    fun getScreenWidth(context: Context): Int {
        val display = getDisplay(context)
        val screenWidth = display.width
        return screenWidth
    }

    /**
     * 获取屏幕高度大小，单位px

     * @param context
     * *
     * @return
     */
    fun getScreenHeight(context: Context): Int {
        val display = getDisplay(context)
        val screenHeight = display.height
        return screenHeight
    }
    /**
     * 获取显示设备参数

     * @param context
     * *
     * @return
     */
    fun getDisplay(context: Context): Display {
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        return wm.defaultDisplay
    }


    fun dp2px(dpValue: Float): Int {
        val scale = Resources.getSystem().displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }


    fun dp2pxOther(dp: Float): Float {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().displayMetrics)
    }

    fun sp2px(sp: Float): Float {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, Resources.getSystem().displayMetrics)
    }

}